23. HAVING
SOLUTION:
- **WHERE** subsets the returned data based on a logical condition.
- **WHERE** appears after the **FROM**, **JOIN**, and **ON** clauses, but before **GROUP BY**.
- **HAVING** appears after the **GROUP BY** clause, but before the **ORDER BY** clause.
- **HAVING** is like **WHERE**, but it works on logical statements involving aggregations.
Questions: HAVING
Use the SQL environment below to assist with answering the following questions. Whether you get stuck or you just want to double check your solutions, my answers can be found at the top of the next concept.
How many of the sales reps have more than 5 accounts that they manage?
How many accounts have more than 20 orders?
Which account has the most orders?
Which accounts spent more than 30,000 usd total across all orders?
Which accounts spent less than 1,000 usd total across all orders?
Which account has spent the most with us?
Which account has spent the least with us?
Which accounts used
facebook
as a channel to contact customers more than 6 times?Which account used
facebook
most as a channel?Which channel was most frequently used by most accounts?
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: sql-evaluator
- Opened files (when workspace is loaded): n/a